package xiaohong.sort;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ShellSortDemo {

    public static void main(String[] args) {
        List<Integer> nums = new ArrayList<>(100000);
        for (int i = 0; i < 100000; i++) {
            nums.add((int)(Math.random() * 1000000));
        }
//        System.out.println("排序之前" + nums);
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println( "希尔排序之前时间" +formatter.format(date));

        int gap = nums.size() / 2;
        while (gap > 0) {
            for (int i = gap; i < nums.size(); i = i + 1) {
                int temp = nums.get(i);
                for (int j = i - gap; j >= 0; j = j - gap) {
                    if (nums.get(j) > temp) {
                        nums.set(j + gap, nums.get(j));
                        nums.set(j, temp);
                    }
                }
            }
            gap = gap / 2;
        }

        Date date1 = new Date();
        System.out.println( "选择排序之后时间" +formatter.format(date1));

//        System.out.println("排序之后"+nums);
    }


}
